package com.stefan.lession02;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestActionEvent2 {

    public static void main(String[] args) {
        // 两个按钮，实现同一个监听
        Frame frame = new Frame("开始--停止");
        Button button1 = new Button("start");
        Button button2 = new Button("stop");

        // 可以显示的定义触发会返回的命令，如果不显示定义会走默认值
        button2.setActionCommand("stop--bth2");

        MyMoniter myMoniter = new MyMoniter();
        button1.addActionListener(myMoniter);
        button2.addActionListener(myMoniter);

        frame.add(button1,BorderLayout.NORTH);
        frame.add(button2,BorderLayout.SOUTH);

        frame.pack();
        frame.setVisible(true);
    }

}

class MyMoniter implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("按钮点击信息：" + e.getActionCommand());
    }
}